<?php


namespace app\decorator;


class RenderToXml extends Decorator
{
    private function decorate($data)
    {
        $doc = new \DOMDocument();
        foreach ($data as $key => $val) {
            $doc->appendChild($doc->createElement($key, $val));
        }
        return $doc->saveXML();
    }

    public function renderData()
    {
        $data = $this->wrapped->renderData();
        return $this->decorate($data);
    }
}